package com.jt.tenant.conn;

import com.jt.tenant.app.JTApplication;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by AD on 2016/5/12.
 */
@HttpInlet(Conn.INLET_GET_CAR_SERIES)
public class GetCarSeries extends JTAsyGet<GetCarSeries.Info> {
    public String token = JTApplication.jtPreferences.readToken();

    public String brandId ;

    public GetCarSeries(String brandId,AsyCallBack<Info> asyCallBack) {

        super(asyCallBack);

        this.brandId = brandId;
    }

    @Override
    protected Info parser(JSONObject object) {

        JSONObject apiTYF = object.optJSONObject("apiTYF");

        JSONObject head = apiTYF.optJSONObject("head");

        Info info = new Info();

        info.msg = head.optString("msg");

        info.code = head.optString("code");

        JSONObject body = apiTYF.optJSONObject("body");

        JSONArray cSlist = body.optJSONArray("list");



        if(cSlist!=null){
            for (int i=0;i<cSlist.length();i++){

                JSONObject object_cs = cSlist.optJSONObject(i);

                CSList mList = new CSList();

                mList.ID = object_cs.optString("id");

                mList.NAME = object_cs.optString("name");

                mList.BRANDID = object_cs.optString("brandId");

                info.csLists.add(mList);
            }
        }else{

            TOAST = "未能获取车辆型号信息，请稍后重试";

        }
        return info;
    }

    public static class Info{
        public String msg;
        public String code;
        public List<CSList> csLists = new ArrayList<>();

    }
    public static class CSList implements Serializable{
        public String  ID,NAME,BRANDID;
    }
}
